<?php
class Teachers {
    public function check_teacher($firstName,$lastName,$mail) // sprawdza, czy dany login jest wolny
    {
		$database = Database::getInstance();
		$check_query = $database->dbh->prepare("SELECT id FROM teacher WHERE firstName='{$firstName}' and lastName='{$lastName}' and mail='{$mail}'");
		$check_query->execute();
		if($check_query->rowCount() > 0){ 
			return 0; // znaleziono w bazie nauczyciela z takimi danymi
		}else{
			return 1; // nie ma jeszcze takiego nauczyciela
		}
    }
	
	public function add_teacher($firstName,$lastName,$mail) // dodaje nauczyciela do bazy
    {
		$database = Database::getInstance();
		$register_query = $database->dbh->prepare("INSERT INTO teacher (firstName,lastName,mail) VALUES ('{$firstName}','{$lastName}','{$mail}')");
		
		if($register_query->execute()){ 
			return 1; // zarejestrowano
		}else{
			return 0; // coś się nie udało
		}
    }
	
	public function get_teachers()
	{
		$database = Database::getInstance();
		$get_query = $database->dbh->prepare("SELECT firstName,lastName,mail FROM teacher");
		$get_query->execute();
		$result = $get_query->fetchAll();
		foreach($result as $id => $teacher) {
			$teacherData[$id]['firstName'] = $teacher['firstName'];
			$teacherData[$id]['lastName'] = $teacher['lastName'];
			$teacherData[$id]['mail'] = $teacher['mail'];
        }
		return $teacherData;
	}
} 

?>